package com.str.tree;
public class TreeTest {

  public static void main(String args[]) {
    // Build a couple of trees, with printouts along the
    // way to test that everything is OK.
    // Ideally, the GTNode would be packaged private from
    // the application program, and all accesses would be
    // through the GenTree interface.  But, I just want to
    // test the functions in a simple way.
    TreeNode root = new TreeNode(new Integer(1));   
    System.out.println("Print the tree with one node");
    TreeOps.print(root);
        
    TreeNode ref = root;     
    TreeOps.insertFirst(ref, new Integer(2));
    System.out.println("Print the tree with two nodes");
    TreeOps.print(root);
    
    ref = ref.leftChild;     
    System.out.println("ref now at node " + ref);

    TreeOps.insertNext(ref, new Integer(3));
    System.out.println("Print the tree with three nodes");
    TreeOps.print(root);
  
    TreeOps.insertNext(ref, new Integer(4));
    System.out.println("Print the tree with four nodes");
    TreeOps.print(root);
  
    ref = ref.rightSib;  
    System.out.println("ref now at node " + ref);
  
    TreeOps.insertFirst(ref, new Integer(5));
    System.out.println("Print the tree with 5 nodes");
    TreeOps.print(root);  
    
    ref = TreeOps.search(root, new Integer(5));
    System.out.println("ref now at node " + ref + "\n");    
        
    TreeNode root2 = new TreeNode(new Integer(11));
    TreeNode ref2 = root2;
    TreeOps.insertFirst(ref2, new Integer(12));
    ref2 = ref2.leftChild;
    TreeOps.insertNext(ref2, new Integer(13));
    System.out.println("Print the tree");
    TreeOps.print(root2);

    TreeOps.insertFirst(ref2, new Integer(42));    
    System.out.println("This is the same tree with 42 added.");
    TreeOps.print(root2);

    TreeOps.removeFirst(ref2);    
    System.out.println("This is the same tree with 42 deleted.");
    TreeOps.print(root2);
    
    TreeOps.removeNext(ref2);    
    System.out.println("This is the same tree with 13 deleted.");
    TreeOps.print(root2);         
  }
}